<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>
<body>
  <div id="app">
    {{obj}}
    <br>
    a: <input type="text" v-model.number="a"><br>
    b: <input type="text" v-model.number="b"><br>
    total: <span>{{total}}</span>
    <button @click="clickHandler">按钮</button>
  </div>
  <script>
    new Vue({
      el: '#app',
      data: {
        a: null,
        b: null,
        total: null,
        obj: {
          name: '张三',
          age: 12
        }
      },
      watch: {
        a(newValue,oldValue) {
          this.total = newValue + this.b
        },
        b(newValue,oldValue) {
          this.total = newValue + this.a
        },
        obj: {
          handler: (newValue,oldValue) => {
            console.log(newValue,oldValue);
          },
          deep: true
        }
      },
      methods: {
        // 1.按钮点击事件处理函数
        clickHandler() {
          this.obj.age ++;
        }
      }
    })
  </script>
</body>
</html>